package com.fjec.market.config;

import com.fjec.common.rabbitmq.BaseCallback;
import com.fjec.market.rabbitmq.SubmitPhyOrderCallback;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AmqpConfig {

    @Bean("phyOrderAmqpTemplate")
    public RabbitTemplate phyOrderAmqpTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        BaseCallback baseCallback = new BaseCallback("MQ_ORDER_TIMEOUT");
        //成功回调
        template.setConfirmCallback(baseCallback);
        //失败回调
        template.setReturnCallback(baseCallback);
        return template;
    }

    @Bean("shopNumAmqpTemplate")
    public RabbitTemplate shopNumAmqpTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        BaseCallback baseCallback = new BaseCallback("MQ_SHOP_NUM");
        //成功回调
        template.setConfirmCallback(baseCallback);
        //失败回调
        template.setReturnCallback(baseCallback);
        return template;
    }

    @Bean("sysMessageAmqpTemplate")
    public RabbitTemplate sysMessageAmqpTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        BaseCallback baseCallback = new BaseCallback("MQ_SYS_MSG");
        //成功回调
        template.setConfirmCallback(baseCallback);
        //失败回调
        template.setReturnCallback(baseCallback);
        return template;
    }

    @Bean("ysRegAmqpTemplate")
    public RabbitTemplate ysRegAmqpTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        BaseCallback baseCallback = new BaseCallback("MQ_YS_REG");
        //成功回调
        template.setConfirmCallback(baseCallback);
        //失败回调
        template.setReturnCallback(baseCallback);
        return template;
    }

    @Bean("preparePayAmqpTemplate")
    public RabbitTemplate preparePayAmqpTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        BaseCallback baseCallback = new BaseCallback("MQ_PREPARE_PAY");
        //成功回调
        template.setConfirmCallback(baseCallback);
        //失败回调
        template.setReturnCallback(baseCallback);
        return template;
    }

    @Bean("ysRegisterResultQueryTemplate")
    public RabbitTemplate ysRegisterResultQueryTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        BaseCallback baseCallback = new BaseCallback("MQ_YSREG_RESULT_QUERY");
        //成功回调
        template.setConfirmCallback(baseCallback);
        //失败回调
        template.setReturnCallback(baseCallback);
        return template;
    }

}
